# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : jwt库的使用.py
# @Author: dongguangwen
# @Date  : 2024-06-22 11:37

import jwt
from datetime import datetime, timedelta

# 添加过期时间
expiration = datetime.utcnow() + timedelta(hours=1)

payload = {'user_id': '123456', 'exp': expiration}
secret_key = 'qwertyuiopasdfghjkl'

token = jwt.encode(payload, secret_key, algorithm='HS256')
print(token)


decoded_token = jwt.decode(token, secret_key, algorithms=['HS256'])
print(decoded_token)

'''
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMTIzNDU2IiwiZXhwIjoxNzE5MDMzOTEzfQ.drBWIF4PT_hak77oGhjZHEK7_ry5iL01VJvSBcsA9Cc
{'user_id': '123456', 'exp': 1719033913}
'''